package com.six.controller;

import com.six.domain.entity.Category;
import com.six.service.CategoryService;
import com.six.util.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/api/category")
@RequiredArgsConstructor
public class CategoryController {

    private final CategoryService categoryService;

    // ✅ 新增分类：前端传店铺id，用户自己输入分类名称
    @PostMapping
    public Result<Void> add(@RequestParam Integer storeId,
                            @RequestParam String name) {
        categoryService.save(name, storeId);
        return Result.success();
    }

    @GetMapping
    public Result<List<Category>> list(@RequestParam Integer storeId) {
        return Result.success(categoryService.listByStore(storeId));
    }

 @DeleteMapping
 public Result<Void>deleteCategoryById(@RequestBody List<Long> ids,
                                 @RequestParam Integer storeId) {
     if (ids == null || ids.isEmpty()) {
         throw new IllegalArgumentException("id 列表不能为空");
     }
     categoryService.deleteCategoryById(storeId, ids);
     return Result.success();
 }

}
